package ophiux.api.sdk.test;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import ophiux.api.sdk.OphiuxApiException;
import ophiux.common.utils.StringUtil;
import ophiux.common.utils.XMLUtil;

public class TEST_XmlUtil {
	
	public static void test_getDocmentElement_success(String xmlStr) throws OphiuxApiException{
		if(StringUtil.isEmpty(xmlStr)){
			 xmlStr = 
					 "<PARAM>"
						+"<HOSPITAL_CODE>111</HOSPITAL_CODE>"
						+"<OCCASION>reg</OCCASION>"
						+"<RESULT>1</RESULT>"
						+"<DEPT_CODE>5436</DEPT_CODE>"
					+"</PARAM>";
		}
	    Element element = XMLUtil.getDocmentElement(xmlStr);
	    System.out.println("element:"+element);
	    Element param = XMLUtil.getChildElement(element,"attach");
	    NodeList nodes = param.getChildNodes();
	    for(int i=0;i<nodes.getLength();i++){
	    	System.out.println(nodes.item(i).getNodeValue());
	    }
		
	}
	
	public static void main(String[] args) throws OphiuxApiException {
		String xmlStrReq = "<xml><appid><![CDATA[wxb50d6933834082a6]]></appid>"+
				"<attach><![CDATA[-1]]></attach>"+
				"<bank_type><![CDATA[CFT]]></bank_type>"+
				"<cash_fee><![CDATA[1]]></cash_fee>"+
				"<fee_type><![CDATA[CNY]]></fee_type>"+
				"<is_subscribe><![CDATA[N]]></is_subscribe>"+
				"<mch_id><![CDATA[1327201101]]></mch_id>"+
				"<nonce_str><![CDATA[1007125159]]></nonce_str>"+
				"<openid><![CDATA[o72wcxIG3Vqw1-KIe0hx4d3sjW4o]]></openid>"+
				"<out_trade_no><![CDATA[9001201606031007001]]></out_trade_no>"+
				"<result_code><![CDATA[SUCCESS]]></result_code>"+
				"<return_code><![CDATA[SUCCESS]]></return_code>"+
				"<sign><![CDATA[2EDCA4512F0978E64BB530C27BDDE014]]></sign>"+
				"<sub_mch_id><![CDATA[1342797001]]></sub_mch_id>"+
				"<time_end><![CDATA[20160603100724]]></time_end>"+
				"<total_fee>1</total_fee>"+
				"<trade_type><![CDATA[JSAPI]]></trade_type>"+
				"<transaction_id><![CDATA[4005092001201606036691908788]]></transaction_id>"+
				"</xml>";
		TEST_XmlUtil.test_getDocmentElement_success(xmlStrReq);
	}
	
}
